﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Windows;

namespace LockCrypt.Firefox {
    /// <summary>
    /// The context encapsulating a request.
    /// </summary>
    public class RequestContext {
        /// <summary>
        /// Gets or sets the remote IP and port.
        /// </summary>
        /// <value>The remote IP and port.</value>
        public string RemoteIP { get; private set; }

        /// <summary>
        /// Gets or sets the socket used to connect.
        /// </summary>
        /// <value>The socket.</value>
        public Socket Socket { get; set; }

        /// <summary>
        /// Gets or sets the buffer of request data.
        /// </summary>
        /// <value>The request buffer.</value>
        public RequestBuffer RequestBuffer { get; set; }
        
        /// <summary>
        /// Initializes an RequestContext from a socket.
        /// </summary>
        /// <param name="sock">The socket.</param>
        public RequestContext(Socket sock) {
            Clear();
            this.Socket = sock;
            var endPoint = sock.RemoteEndPoint as IPEndPoint;
            this.RemoteIP = string.Format("{0}:{1}", endPoint.Address.ToString(), endPoint.Port);
            this.RequestBuffer = new RequestBuffer();
        }

        /// <summary>
        /// Resets the RequestContext.
        /// </summary>
        public void Clear() {
            Socket = null;
            RemoteIP = null;
        }
    }
}
